home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2927 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.6 KB

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Floating point calculation order
  5. Date: 25 Jan 1996 01:10:45 GMT
  6. Organization: Los Alamos National Laboratory
  7. Message-ID: <TANMOY.96Jan24181045@qcd.lanl.gov>
  8. References: <m0tedv8-0002eqC@sice.nsk.su> <3104c6d9.134061184@nntp.ix.netcom.com>
  9.     <TANMOY.96Jan23144637@qcd.lanl.gov> <DLpF0C.IH4@microunity.com>
  10. NNTP-Posting-Host: qcd.lanl.gov
  11. Mime-Version: 1.0
  12. Content-Type: text
  13. In-reply-to: toms@MicroUnity.com's message of Wed, 24 Jan 1996 21:14:36 GMT
  14.  
  15. --text follows this line--
  16. In article <DLpF0C.IH4@microunity.com> toms@MicroUnity.com (Tom
  17. Sanders) writes: 
  18. <snip>
  19.    |> I am almost certain you write `a + b * c' contrary to your claim. Do
  20.    |> you mean `a + (b * c)' or `(a + b) * c' when, if, you do it? If you do
  21.    |> not, you are in a very small minority.
  22. <snip>
  23.    Sorry Tanmoy you'd be wrong, I do write `a + (b * c)' not `a + b * c' .
  24.  
  25. I see. I had not expected such an extreme position: but de gustabis
  26. non est disputandum. I am used to writing long expressions, and after
  27. a point parentheses obscure rather than reveal.
  28.  
  29.    Do I need to , no of course not.  I prefer to for clarity.  If I specify
  30.    exactly what I want when I write it, there is little doubt in the future
  31.    if I or someone else is debugging a problem.  If I leave the parentheses
  32.    out, I or someone else may wonder whether it was intended to be 
  33.    `(a + b) * c' and waste time in a useless direction.
  34.  
  35. I must admit that I sometimes use space and alignment for these
  36. purposes, but very rarely use parentheses for this purpose. I sometime
  37. do use parentheses when evaluation order does not matter and I want to
  38. stress the logical unity of a piece of the expression: even that is
  39. rare though.
  40.  
  41.    As to the original equation `p * q / r' , I would argue that parentheses
  42.    are certainly necessary.  There is a slight numeric difference between
  43.    `(p * q) / r' and `p * (q / r)' .  By specifying I am sure the order I
  44.    prefer will be used no matter what compiler I am using.
  45.  
  46. Even in non-ANSI C, there was no guarantee that the compiler will
  47. respect your parentheses. However, if you meant not `any' compiler:
  48. but any of a number of compilers, at least one of which is
  49. non-conformant, that you are likely to work on, I agree with you.
  50.  
  51. When I write C, I assume ANSI conformance for parts which are not
  52. time-critical. Parts which are time-critical, I have to code afresh
  53. for every machine anyway: this, at least so I hope, is not the
  54. experience of everyone.
  55.  
  56. In ANSI C, a compiler is just plain wrong if it treats p * q / r as p
  57. * (q/r), if there is a difference between them (yes, I mean if
  58. numerically, there is a difference between them). The only thing ANSI
  59. C permits is that intermediate results may be help at higher precision
  60. than stored results: no reordering is allowed if it is visible by the
  61. program. The rules in FORTRAN (which I use more often for numerical
  62. work) are different.
  63.  
  64. In any case, such stylistic issues can become religious. Some of my
  65. styles, I am sure, are religiously hated by other people. I see what
  66. you are saying, I think; but I do not agree with that style.
  67.  
  68. Cheers
  69. Tanmoy
  70. --
  71. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  72. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  73. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  74. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  75. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  76. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  77.